/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cx1.model.utils;

import org.apache.commons.lang.StringUtils;

/**
 *
 * @author ECH
 */
public class RateUtils {
    
    public static double toDouble(String strRate) {
        double rate = 0.0;
        try {
            String clean = strRate.replaceAll(",", "");
            if (clean != null && !StringUtils.isEmpty(clean.trim())) {
                rate = Double.parseDouble(clean);
            }            
        } 
        catch (Exception ex) {
            ex.printStackTrace();
        }
        return rate;
    }
    
    public static float strRateToNum(String rate) {
        float numRate = 0;
        String strRate = new String(rate);
        try {
            strRate = strRate.trim();
            strRate = strRate.replaceAll("(?<=^\\d+)\\.0*$", "");
            strRate = strRate.replaceAll(",", "");
            numRate = Float.parseFloat(strRate);
        }
        catch (Exception ex) {
            
        }
        return numRate;
    }
    
    public static void main (String[] argv) {
        System.out.println("CX: " + RateUtils.toDouble("10,000.45"));
    }
}
